package com.digitalchina.frame.core.spring;

import javax.servlet.ServletContextEvent;

import org.springframework.web.context.ContextLoaderListener;


public class ContainerContextLoaderListener extends ContextLoaderListener {

	public ContainerContextLoaderListener() {
	}

	public void contextInitialized(ServletContextEvent event) {
		if (canInitialiseContainer()) {
			super.contextInitialized(event);
			postInitialiseContext(event);
		}
		SpringContainerContext springCC = getNewSpringContainerContext();
		springCC.setServletContext(event.getServletContext());
		ContainerManager.getInstance().setContainerContext(springCC);
		springCC.contextReloaded();
	}

	protected void postInitialiseContext(ServletContextEvent servletcontextevent) {
	}

	protected SpringContainerContext getNewSpringContainerContext() {
		return new SpringContainerContext();
	}

	public boolean canInitialiseContainer() {
		return true;
	}
}